{include file="header/index" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
.file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
.file-item .info{overflow: hidden;}
.uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="container bgwhite">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑配置</h5>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                    <div class="backbtnwrap fr">
                        <button type="button" class="btn backbtn" onclick="returnBack(this)">返回</button>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="editeConf" id="editeConf" method="post" action="edite_ext">
                        <input type="hidden" name="id" value='{$conf.id}'>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置项：</label>
                            <div class="input-group col-sm-4">
                                <input id="key" type="text" class="form-control" name="key"  value='{$conf.key}'>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">配置说明：</label>
                            <div class="input-group col-sm-4">
                                <input id="comment" type="text" class="form-control" name="comment" value='{$conf.comment}'>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="btn-group" style="width: 100%">

                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" id='addMoreConf'>
                                <?php if (!empty($confs)) {  ?>
                                {foreach name="$confs" id="val" key="key"}

                                    <label class="col-sm-3 control-label">具体配置：</label>
                                    <div class="row">
                                      <div class="col-lg-3">
                                        <div class="input-group">
                                          <span class="input-group-addon">配置名</span>
                                          <input type="text" class="form-control"  name='value[]' value='{$key}'>
                                        </div><!-- /input-group -->
                                      </div><!-- /.col-lg-6 -->
                                      <div class="col-lg-3">
                                        <div class="input-group">
                                          <span class="input-group-addon">配置值</span>
                                          <input type="text" class="form-control" name='val[]' value='{$val}'>
                                        </div><!-- /input-group -->
                                      </div><!-- /.col-lg-6 -->
                                    </div><!-- /.row -->
                                    <div class="hr-line-dashed"></div>
                                   {/foreach}
                                <?php  } ?>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <button class="btn btn-info" type="button" id='addMoreConfToHtml'>添加</button>
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
</div>


<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/js/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/images/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
        '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });


</script>
<script type="text/javascript">

    $(function(){
        $('#addMoreConfToHtml').click(function(){
            var OneConf = '<div class="hr-line-dashed"></div><label class="col-sm-3 control-label">具体配置：</label><div class="row"><div class="col-lg-3">';
                OneConf +='<div class="input-group"><span class="input-group-addon">配置名</span><input type="text" class="form-control"  name="value[]" value="">';
                OneConf +='</div> </div> <div class="col-lg-3"><div class="input-group"><span class="input-group-addon">配置值</span>';
                OneConf +='<input type="text" class="form-control" name="val[]" value=""></div> </div></div>';
                $('#addMoreConf').append(OneConf);

        })
    })

    $(function(){
        $('#editeConf').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#key').val())){
                layer.msg('配置名称', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

     }

        function complete(data){
            if(data.code == 1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                    window.location.href="{:url('config/extend')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });


    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }



</script>
</body>
</html>
